# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
root=TreeNode(4)
root.left=TreeNode(9)
root.right=TreeNode(0)
root.left.left=TreeNode(5)
root.left.right=TreeNode(1)
def dfs(root,path,nodeSum):
    #出口条件
    if root.left==None and root.right==None:
        path.append(nodeSum*10+root.val)
        return None
    nodeSum=nodeSum*10+root.val
    if root.left:
        dfs(root.left,path,nodeSum)
    if root.right:
        dfs(root.right,path,nodeSum)

def sumNumbers(root):
    if not root:
        return 0
    path=[]
    dfs(root,path,0)
    sum=0
    for i in path:
        sum+=i
    print("sum:",sum)

sumNumbers(root)